package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


public class OrderConfirmVo {


    //收货地址
    @Getter @Setter
    List<MemberAddressVo> address;

    //所有选中的购物项
    @Getter @Setter
    List<OrderItemVo> items;

    //发票记录


    //优惠券信息
    /**
     * 积分
     */
    @Getter @Setter
    private Integer integration;

//    BigDecimal total; //订单总额，需要计算


    //防重令牌 TODO
    @Getter @Setter
    String orderToken;


    public int getCount(){

        int i = 0;
        if(items!=null){
            for(OrderItemVo item: items){
                i+=item.getCount();
            }
        }

        return i;
    }

    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){

            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getTotalPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum =  sum.add(multiply);

            }
        }


        return sum;


    }

    @Getter @Setter
    Map<Long,Boolean> stocks;

    //应付价格
    public BigDecimal getPayPrice(){

        return getTotal();
    }
}
